﻿using Phones.DataLayer;
using Phones.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Phones.ViewModel
{
    public class TreeRootViewModel : TreeViewItemViewModel
    {
        private TreeElement _treeElement;
        private TreeElementRepository db;

        public TreeRootViewModel()
            : base(null, false)
        {
            db = new DataLayer.TreeElementRepository();
            _treeElement = db.GetRoot();
            LoadChildren();
        }

        protected override void LoadChildren()
        {
            Children.Clear();
            foreach (var child in _treeElement.Children)
            {
                Children.Add(new TreeElementNodeViewModel(this, child));
            }
        }
    }
}
